﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Regions;
using System.Windows;
using RentAWorker.Business.Interfaces;
using WorkerManagement.WorkerList;
using RentAWorker.Management.Infrastructure;
using Microsoft.Practices.Composite.Presentation.Commands;

namespace WorkerManagement
{
    public class ModuleController
    {
        private IRegionManager RegionManager { get; set; }
        private IUnityContainer Container { get; set; }

        public ModuleController(IUnityContainer container, IRegionManager regionManager)
        {
            this.Container = container;
            this.RegionManager = regionManager;
        }

        public void Run()
        {
            IExtendableShell shell = this.Container.Resolve<IExtendableShell>();

            shell.AddToolBarItem(this, "Worker List", null, 
                new DelegateCommand<object>(DisplayWorkerList));
        }

        private void DisplayWorkerList(object nullparam)
        {
            IWorkerListPresentationModel pm = this.Container.Resolve<IWorkerListPresentationModel>();

            this.RegionManager.AddToRegion("MainRegion", pm.View);
            this.RegionManager.Regions["MainRegion"].Activate(pm.View);
        }
    }
}
